<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/head_latest.inc"%>
<title>流程跟踪意见填写-${basePageTitle}</title>
</head>
<body>
<!-- 流程跟踪意见填写(内嵌到页面) -->
 <div id="opinionPanel" style="margin:5px 10px;">
        <form id="opinionform" method="post">
        	<input type="hidden" name="boId" id="boId" value="${param.boId}" class="field"/>
        	<input type="hidden" name="mainBoId" id="mainBoId" value="${param.mainBoId}" class="field"/>
        	<input type="hidden" name="busiType" id="busiType" value="${param.busiType}" class="field"/>
        	<input type="hidden" name="flowId" id="flowId" value="${param.flowId}" class="field"/>
        	<input type="hidden" name="worklistId" id="worklistId" value="${param.worklistId}" class="field"/>
        	<input type="hidden" name="routeId" id="routeId" value="${param.routeId}" class="field"/>
        	<input type="hidden" name="parentNodeInstanceId" id="parentNodeInstanceId" value="${param.parentNodeInstanceId}" class="field"/>
        	<input type="hidden" name="handlerValue" id="handlerValue" value="" />
        	<input type="hidden" name="handlerText" id="handlerText" value="" />
        	<c:if  test="${!isStart }">
        	<div class="l-group l-group-hasicon">
							<img src="${baseURL }/themes/default/icons/32X32/communication.gif" style="width:16px;height:16px;"/>
							<span style="font-weight: bold;">流程意见填写&nbsp;&nbsp;</span>
							<button id="btnSaveMyOpinion">保存为我的常用意见</button>
							<button id="btnDelMyOpinion">删除我的常用意见</button>
							<button id="btnClearOpinion">清空意见</button>
			</div>
        	<table cellpadding="0" cellspacing="0" class="l-table-edit">
        		<tr height="40">
					<td align="right">我的常用意见：</td>
					<td align="left">
						<select name="myOpinion" id="myOpinion" style="width: 350px">
								<option value=''>--请选择--</option>
								<c:forEach var="o" items="${myOpinions}">
									<option value="${o.id}">${o.opinion}</option>
								</c:forEach>
						</select>
					</td>	
				</tr>
				<tr height="40">
					<td align="right">意见填写：</td>
					<td align="left">
						<textarea cols="100" rows="4" name="opinion" id="opinion" style="width: 350px;"
							validate="{maxlength:200}"></textarea>
					</td>	
				</tr>
			</table>
			</c:if>
			<div class="l-group l-group-hasicon">
				<img src="${baseURL }/themes/default/icons/32X32/communication.gif" style="width:16px;height:16px;"/>
				<span style="font-weight: bold;">路由选择&nbsp;&nbsp;</span>
			</div>
			<table cellpadding="0" cellspacing="0" class="l-table-edit">
				<tr height="40">
					<td align="right" style="padding-left:30px;">${routeSelect.routeName}&nbsp;&nbsp;->&nbsp;&nbsp;${routeSelect.nextNodeName}</td>
				</tr>
			</table>
 			<c:if test="${routeSelect.hasHandlerSelect}">
 				<div class="l-group l-group-hasicon">
					<img src="${baseURL }/themes/default/icons/32X32/communication.gif" style="width:16px;height:16px;"/>
					<span style="font-weight: bold;">下一环节处理人&nbsp;&nbsp;</span>
					<button id="btnReselected">重新选择</button>
					<button id="btnDeselected">删除</button>
					<button id="btnAllselected">全选</button>
				</div>
				<table cellpadding="0" cellspacing="0" class="l-table-edit">
					<tr height="40">
						<td align="right">处理人选择：</td>
						<td align="left" id="handlerList">
							<c:forEach var="o" items="${routeSelect.handlers}">
								<span><input type="checkbox" name="handler" value="${o.id}" checked="checked"/>${o.name}&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</c:forEach>
						</td>	
					</tr>
				</table>
			</c:if>
			 <input type="hidden" name="handlers" id="handlers"/>
        </form> 
</div>
  <script type="text/javascript">
//显示成功提示窗口
  LG.showWarn = function (message, callback)
  {
      if (typeof (message) == "function" || arguments.length == 0)
      {
          callback = message;
          message = "警告!";
      }
      $.ligerDialog.warn(message, '提示信息', callback);
  };
  	var hasHandlerSelect = ${routeSelect.hasHandlerSelect};
  	  //保存我的常用意见
  	  $("#btnSaveMyOpinion").click(function(){
  		var val = $("#opinion").val()
  		if($.trim(val)==''){
  			LG.showWarn("请先填写意见!");
  			return false;
  		}else if($.trim(val).length > 50){
  			LG.showWarn("我的常用意见长度不可超过50个字符!");
  			return false;
  		}
  		  $.post("${baseURL}/process/myopinion/personopinionsave/save.do", 
  				  {opinion : $.trim(val)}, 
  				  function(data){
  			  		if(data.hasOk){
  			  			LG.showSuccess("已保存!",function(){
  			  				var $OPT = $("<option>");
  			  				$OPT.attr("value", data.bean.id);
  			  				$OPT.text($("#opinion").val());
  			  				$("#myOpinion").append($OPT);
  			  			});
  			  		}else{
  			  			LG.showError(data.message);
  			  		}
  		  });
  		return false;
  	  });
  	 //删除我的常用意见
  	  $("#btnDelMyOpinion").click(function(){
  		var sels = $("#myOpinion").children(":selected");
  		if(!sels || sels.length == 0 || sels.val()==''){
  			LG.showError("请先从下面的“我的常用意见”下拉选择要删除的意见项!");
  			return false;
  		}
  		$.post("${baseURL}/process/myopinion/personopiniondelete/delete.do", 
				  {ids : sels.val()}, 
				  function(data){
			  		if(data.hasOk){
			  			LG.showSuccess("已删除!",function(){
			  				sels.remove();
			  			});
			  		}else{
			  			LG.showError(data.message);
			  		}
		  });
  		return false;
	  });
  	 //清空我的常用意见
  	  $("#btnClearOpinion").click(function(){
  		$("#opinion").val("");
  		return false;
	  });
  	 //重新选人
  	  $("#btnReselected").click(function(){
	  		$(this).sdAddressBook({type:20, manage:3, multi: 'n', 
	  			onReturn : function(users){
 	  				if(!users || users.outputValue <= 0) return false;
	  				var handlers = $.sdAddressBook.parseValues(users.outputValue);
 	  				for(var i = 0 ;i < handlers.length; i++){
	  					var handler = handlers[i];
	  					 
	  					var $span = $("<span>");
	  					$span.append('<input type="checkbox" name="handler" value="'+handler.id+'" checked="checked"/>'+handler.name);
	  					$span.append('&nbsp;&nbsp;&nbsp;&nbsp;');
	  					$("#handlerList").append($span);
 	  				}
  	  			 return false;
	  		}});
    		return false;
	  });
  	 //删除
  	 $("#btnDeselected").click(function(){
  		var handler = $("input[name='handler']:checked");
  		if(!handler || handler.length ==0){
   		  LG.showWarn("没有选定的处理人!");
   		  return false;
   	    }
  		handler.parent().remove();
  		return false;
  	 });
  	 //全选
  	 $("#btnAllselected").click(function(){
  		var state = $("input[name='handler']:first").attr("checked");
  		$("input[name='handler']").attr("checked", !state);
  		return false;
  	 });
      //编辑，新增
	  var mainform = $("#opinionform");
	  //mainform.ligerForm();
      //添加验证
     jQuery.metadata.setType("attr", "validate"); 
     LG.validate(mainform);
     $("#myOpinion").change(function(){
    	 var sels = $(this).children("option:selected");
    	 if(sels.length >= 0 && $.trim(sels.val())!='')
    		 $("#opinion").val(sels.text());
    	 return false;
     });
     
     //提交
     function FF_Submit(callback, isStart){ 
    	 var action = "${baseURL}/process/gtasks/submit/next.do";//提交
    	 if(isStart) 
    		 action = "${baseURL}/process/gtasks/submit/start.do";//发起
    	 var handler = $("input[name='handler']:checked");
 	   	 if(hasHandlerSelect && (!handler || handler.length ==0)){
	   		  LG.showWarn("没有选定的处理人!", callback);
	   		  return false;
	   	 }
 	   	 var str = ""; 
 	   	 //20!@!罗广亨!@!2c90815444b8eef00144b8f0ca0800a6,20!@!余君劭!@!2c90815444b8eef00144b8f0ca0900b0
 	   	 $("input[name='handler']:checked").each(function(){
 	   		$("#handlerList").append('<input type="hidden" name="handler" value="'+$(this).val()+'" />');
 	   		/*  var temp = '20!@!'+jQuery.trim($(this).parent().text())+'!@!'+$(this).val()+",";
 	   		 str += jQuery.trim(temp); */
 	   	 });
 	   	 /* alert(action);
 	   	 alert(str); */
 	   	 // $("#handlers").val(str);
		  mainform.attr("action", action);
      	  LG.submitForm(mainform, function (data) {
              if (data && data.hasOk) {  
              		LG.showSuccess('操作成功', function () { 
              			callback(data);
                    });                   
              } else {
              		LG.showError('操作失败:' + data.message, function(){
              			callback(data);
              		});
              }
          });
    }
  </script>